package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"yzy6.26exam/api/request"
	"yzy6.26exam/internal/bao"
	"yzy6.26exam/internal/moble"
)

func VideoPush(context *gin.Context) {
	var video_push request.VideoPush
	if err := context.ShouldBind(&video_push); err != nil {
		context.JSON(http.StatusBadRequest, gin.H{
			"code":    200,
			"message": "解析失败",
			"data":    err.Error(),
		})
		return
	}
	var video = moble.Video{
		UserId:     int32(video_push.UserId),
		TitleImage: video_push.ImageUrl,
		VideoUrl:   video_push.VideoUrl,
		Title:      video_push.Title,
		Des:        video_push.Des,
	}
	if err := bao.Create(&video); err != nil {
		context.JSON(http.StatusOK, gin.H{
			"code":    200,
			"message": "上传失败",
			"data":    err.Error(),
		})
		return
	}
	context.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "视频发布成功",
	})
}
